﻿namespace EntLibContrib.Common.TestSupport
{
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    public static class AssertExtensions
    {
        public static void Throws<T>(Action action)
        {
            Throws<T>(action, null);
        }

        public static void Throws<T>(Action action, string message)
        {
            try
            {
                action();
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(T));
            }
        }

        public static void DoesNotThrow(Action action)
        {
            DoesNotThrow(action, null);
        }

        public static void DoesNotThrow(Action action, string message)
        {
            try
            {
                action();
            }
            catch (Exception)
            {
                Assert.Fail(message);
            }
        }
    }
}
